import requests

from datetime import datetime
from urllib.parse import urlencode
from langchain_core.tools import tool

import sys
import os
sys.path.append(os.path.dirname(os.path.abspath(__file__)))

from commit_func import get_token

@tool
def get_duration_vacation(user_id, leavetype):
    """根据用户输入的工号(user_id)和假期类别(leavetype)，返回用户leavetype的休假时长"""
    base_url = 'http://192.168.22.92:8080/portal/api/emphelp/leave/calHasSumhour'

    header = {
        'token' : get_token(user_id),
        'Content-Type': 'application/json'
    }

    today = datetime.now()

    param = {
        "leaveID": "3e09fb44-596a-4008-b90b-4259d2b1c785",
        "leaveyear": str(today.year),
        "leavemonth": str(today.month),
        "leavetype": leavetype,
        "pk_leavetype": "1002Z710000000021ZLJ"
    }
    
    # 使用urllib.parse.urlencode将参数转换为URL查询字符串
    query_string = urlencode(param)
    url = f"{base_url}?{query_string}"
    
    response=requests.post(url, headers=header)
    # print(response.json())
    return response.json()

# if __name__ == "__main__":
#     get_duration_vacation('035556', "年假")